﻿<%@ Control Language="C#" Inherits="Core.Web.Code.UI.Controls.ViewPost" %>
<%@ Register Src="ChildControls/BreadNavigator.ascx" TagName="BreadNavigator" TagPrefix="DFlying" %>
<DFlying:BreadNavigator ID="BreadNavigator1" runat="server" />
<div id="topic_Container">
    <div id="Pager" class="page">
    </div>
    <br />
    <asp:Repeater ID="rptTopic" runat="server">
        <HeaderTemplate>
            <ul>
                <li><a href="javascript:void(0)" onclick='getPostsByTopic("0","0")'>全部分类</a></li>
        </HeaderTemplate>
        <ItemTemplate>
            <li><a href="javascript:void(0)" onclick='getPostsByTopic("<%# Eval("ID") %>","<%#Eval("ModuleID") %>")'>
                <%# Eval("Name") %></a></li>
        </ItemTemplate>
        <FooterTemplate>
            <li><a href="javascript:void(0)" onclick='AjaxState(3)'>候选区</a></li>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
</div>
<div id="Post_Container" class="post-list">
    <h4>
        <p>
            筛选：<a href="javascript:;" id="filter_special" onclick="showMenu(this.id)">全部主题</a><span
                class="arrow-icon"></span>&nbsp;<a href="javascript:;" id="filter_dateline" onclick="showMenu(this.id)">全部时间</a><span
                    class="arrow-icon">&nbsp;</span>&nbsp; <a href="javascript:;" id="filter_orderby"
                        onclick="showMenu(this.id)">排序</a><span class="arrow-icon">&nbsp;</span>&nbsp;
            <a href="javascript:;" onclick="javascript:AjaxState(0)">精华</a><a href="javascript:;"
                onclick="javascript:AjaxState(1)"> 推荐</a><a href="javascript:;" onclick="javascript:AjaxState(2)">热门</a>
        </p>
        <!--全部时间-->
        <div id="filter_dateline_menu" class="p_pop" style="display: none; clear: both;">
            <ul>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time0",$(this).text(),"filter_dateline")'>
                    全部时间</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time1",$(this).text(),"filter_dateline")'>
                    一天</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time2",$(this).text(),"filter_dateline")'>
                    两天</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time3",$(this).text(),"filter_dateline")'>
                    一周</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time4",$(this).text(),"filter_dateline")'>
                    一个月</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("time5",$(this).text(),"filter_dateline")'
                    style="border: 0px;">三个月</a></li>
            </ul>
        </div>
        <!--全部主题-->
        <div id="filter_special_menu" class="p_pop" style="display: none; clear: both;">
            <ul>
                <li><a href="javascript:;" onclick='javascript:ajaxData("theme0",$(this).text(),"filter_special")'>
                    全部主题</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("theme1",$(this).text(),"filter_special")'>
                    投票</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("theme2",$(this).text(),"filter_special")'>
                    活动</a></li>
            </ul>
        </div>
        <!--排序-->
        <div id="filter_orderby_menu" class="p_pop" style="display: none; clear: both;">
            <ul>
                <li><a href="javascript:;" onclick='javascript:ajaxData("sort0",$(this).text(),"filter_orderby")'>
                    默认排序</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("sort1",$(this).text(),"filter_orderby")'>
                    发帖时间</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("sort2",$(this).text(),"filter_orderby")'>
                    回复</a></li>
                <li><a href="javascript:;" onclick='javascript:ajaxData("sort3",$(this).text(),"filter_orderby")'>
                    查看</a></li>
            </ul>
        </div>
    </h4>
    <div id="post_list_main">
        <!--帖子列表-->
    </div>
</div>
<script type="text/javascript">
    var urldata = ["0", initModuleId(), "", "", "", "1", "-100"]; //分类、模块、排序、时间、主题、页码、（精华|推荐|热门）
    function getPostsByTopic(topicId, moduleId) {
        urldata = ["0", initModuleId(), "", "", "", "1", "-100"]; //重新点击分类后重置
        urldata[0] = topicId;
        //重新点击分类后重置
        $('#filter_dateline').text('全部时间');
        $('#filter_special').text('全部主题');
        $('#filter_orderby').text('默认排序');
        $('#post_list_main').html('Loading...');
        ajaxPost();
    }

    function showMenu(id) {
        $('#' + id + '_menu').toggle().siblings('div').hide();
    }

    function PageAjax(page) {
        urldata[5] = page;
        ajaxPost();
    }

    function ajaxData(flag, txt, sender) {
        if (flag.indexOf('sort') > -1)
            urldata[2] = flag; //排序
        if (flag.indexOf('time') > -1)
            urldata[3] = flag; //时间
        if (flag.indexOf('theme') > -1)
            urldata[4] = flag; //主题
        if (flag.indexOf('theme0') > -1)
            urldata = ["0", initModuleId(), "", "", "", "1", "-100"];
        //alert(urldata);
        $('#' + sender + '').text(txt);
        ajaxPost();
        $('div.p_pop').hide();
    }

    function AjaxState(state) {
        urldata = ["0", initModuleId(), "", "", "", "1", "-100"];
        urldata[6] = state;
        ajaxPost();
    }

    function ajaxPost() {
        $('#post_list_main').html("loading...");
        var url = 'AjaxService/AjaxPost.ashx?urldata=' + urldata;
        $.ajax({
            url: url,
            type: 'post',
            cache: false,
            success: function (data) {
                var json = $.parseJSON(data);
                $('#post_list_main').html(json[1]);
                $('#Pager').html(json[0])
            },
            error: function () {
                alert("error");
                alert(xhr.responseText);
            }
        })
    }

    //获取url query
    function getRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    //初始化模块id
    function initModuleId() {
        var Request = new Object();
        Request = getRequest();
        return Request['mid'];
    }

    $(function () {
        $('#topic_Container li:eq(0) a').click();
    })
</script>
